package com.wt.springsamples.controller;

import com.wt.springsamples.common.ApiResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 实现ErrorController会使ErrorMvcAutoConfiguration中自动注册的BasicErrorController失效
 */
//@Controller
public class CustomErrorController  implements ErrorController {

    @RequestMapping("/error")
    @ResponseBody
    public ApiResult error(HttpServletRequest request, HttpServletResponse response) throws Exception {
        return ApiResult.fail("请求错误！");
    }
}
